# time.localtime() # 精度到妙
# 改变时区

# UTC时间就是指通用时间, 没有时区
# # (了解即可
#  os.environ['TZ']='US'
#  time.tzset()
# 时间戳
# 时间戳：时间戳是从1970年1月1日（UTC/GMT的午夜）开始经过的秒数，不考虑闰秒
# time.time()  # 单位是秒, 精度是到微秒
# 时间格式转换
import time
print(time.localtime())

# time.struct_time -> str
# time.strftime("%Y-%m-%d %H:%M:%S", time.struct_time
print(time.strftime("%Y-%m-%d %H-%M-%S") ) #默认调用当前时间
print(time.strftime("%Y/%m/%d %H-%M-%S",time.localtime()) ) #换/,加上time.localtime()，效果一样


# str -> time.struct_time
# time.strptime("2020-11-05 21:50:36", "%Y-%m-%d %H:%M:%S")
print(time.strptime("2020-11-7 7:56:59" ,"%Y-%m-%d %H:%M:%S"))
print(time.strptime("2020/11/7 7:56:59" ,"%Y/%m/%d %H:%M:%S"))    #换一种写法，无效...

# time.struct_time -> tuple
print(tuple(time.localtime()))
now=time.localtime()  #以下3行，换一种写法
print(now)
print(tuple(now))

# tuple(time.struct_time)
# tuple -> time.struct_time
print(time.struct_time(tuple(now)))
print(list(now))    #转成list试试
# time.struct_time(tuple)
# time.struct_time -> timestamp
print(time.localtime(time.time()))   #提供了有时区的接口
print(time.gmtime(time.time()))     #gmtime没有时区

# time.localtime(timestamp) # 提供了有时区接口
# time.gmtime(timestamp) # 没有时区
# timestamp -> time.struct_time  （以上：时间戳转为时间格式
print(now)
print(time.mktime(now))  #时间精度的丢失
# print(time.mktime(time.time()))

# time.mktime(time.struct_time)  #时间精度的丢失


# 时间运算
#
# 只能通过时间格式->元组, 然后创建新元组的方式来新建一个新的时间
#
# 时间休眠
#
# time.sleep()
# datetime
#
# *下面教学只使用datetime.datetime模块
#
# from datetime import datetime
# 提供了处理日期和时间的类
from datetime import datetime
print(dir(datetime))
# 查看时间
print(datetime.today())
print(datetime.now(tz=None)) #now可以指定时区
print(datetime.utcnow())   #返回utc时间
# datetime.today()
# datetime.now(tz=None)  # 可以指定时区
# datetime.utcnow()
# 时间格式的转换
#
# datetime.datetime -> str
print('---')
now=datetime.now()
print(now)
print(now.strftime("%Y-%m-%d %H:%M:%S"))

# [datetime.datetime].strftime("%Y-%m-%d %H:%M:%S")
# str -> datetime.datetime
print('-')
now_str=now.strftime("%Y-%m-%d %H:%M:%S")
print(datetime.strptime(now_str,"%Y-%m-%d %H:%M:%S"))

# datetime.strptime(str, "%Y-%m-%d %H:%M:%S")
# datetime.datetime -> timetuple -> tuple
print(now.timetuple())
print(tuple(now.timetuple()))

# tt = [datetime.datetime].timetuple()
# tuple(tt)
# tuple -> datetime.datetime
print('--')
t=tuple(now.timetuple())
new_t=t[:-3]
print(datetime(*new_t))
print(*new_t)
print(new_t) #√
# t = (2020, 11, 5, 22, 1
# 4, 17, 3, 310, -1)
# new_t = t[:-3]
# datetime(*t)
# datetime.datetime -> timestamp
print(now.timestamp())
# [datetime.datetime].timestamp()
# timestamp -> datetime.datetime
print('-')
print(datetime.fromtimestamp(now.timestamp()))
# datetime.fromtimestamp(timestamp)
# 时间运算
#
# from datetime import timedelta
#
# [datetime.datetime] + timedelta(hours=1)
print('hhh')
from datetime import timedelta
print(now)
print(now+timedelta(hours=1))
print('以下是函数：')


def get_date(days):
    value=int(input("请输入一个整数："))
    sturct_time = now+ timedelta (days=value)
    print(sturct_time)
    return sturct_time

get_date(2)